package com.neusoft.neuiotms.dcvm.fixture;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.neusoft.neuiotms.dcvm.enums.DictionaryType;
import com.neusoft.neuiotms.dcvm.model.Dictionary;
import com.neusoft.neuiotms.dcvm.repository.DictionaryRepository;

@Component
public class DcvmInitialDataFixture implements CommandLineRunner {

    @Autowired
    private DictionaryRepository dictionaryRepository;

    @Override
    public void run(String... args) throws Exception {
        this.init();
    }

    private void init() {
        if (this.dictionaryRepository.count() > 0) {
            return;
        }

        final String[][] data = new String[][] {
                new String[] {"1", "建筑物", "0", "modelType" },
                new String[] {"2", "设备", "1", "modelType" },
                new String[] {"3", "装饰物", "2", "modelType" },
                new String[] {"UNITY5.3", "UNITY5.3", "0", "versionType" },
                new String[] {"WEBGL2018", "WEBGL2018", "1", "versionType" }
        };

        for (final String[] element : data) {
            final Dictionary dict = new Dictionary();
            dict.setCode(element[0]);
            dict.setText(element[1]);
            dict.setSort(Integer.valueOf(element[2]));
            dict.setType(DictionaryType.valueOf(element[3]));

            this.dictionaryRepository.save(dict);
        }
    }

}
